import threading
import time

import opcua_worker
from examples.my_model import HkBasePoint
import my_mysql

ret = my_mysql.helper.get_session().query(HkBasePoint).filter(HkBasePoint.point_address.like('ANDON_DB.ANDON[9].%')).order_by(HkBasePoint.id).all()

dict_list = {}

for item in ret:
    if item.device_channel_id in dict_list:
        data_list = dict_list.get(item.device_channel_id)
        data_list.append(item)
        dict_list[item.device_channel_id] = data_list
    else:
        data_list = [item]
        dict_list[item.device_channel_id] = data_list

# print(dict_list)
print("---------------------------------------------------------------------------")

if __name__ == "__main__":

    for k, v in dict_list.items():
        # print(k, v)
        t = threading.Thread(target=opcua_worker.worker, args=(k, v))
        t.start()

    while True:
        time.sleep(100)
